# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=gomuks
pkgver=0.3.0
pkgrel=2
pkgdesc="A terminal based Matrix client written in Go"
arch=(loong64 x86_64)
url="https://github.com/tulir/gomuks"
license=(AGPL3)
depends=(glibc)
makedepends=(libolm go)
source=($url/archive/v$pkgver/$pkgname-v$pkgver.tar.gz)
sha512sums=('9f001db7b926779f4f33dd0fa3c5d4a88ec31862ecbcfd529846b187d3ac26f70d2836250bc827a8852b8af62a32a3e2e20861f849cfa2d39bf1784967c4c80a')
b2sums=('5481e885f7a92b17a4ff7e95304080fe3d9455afd84fc708e3630a89f6df9fc2c712ad27a1d0bb351bd1a6af14cc554ea4556444e022909b4ccdd8d825911cfc')

prepare() {
  mkdir -vp $pkgname-$pkgver/build
}

build() {
  cd $pkgname-$pkgver
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOPATH="${srcdir}"
  export GOFLAGS="-buildmode=pie -mod=readonly -modcacherw"

  go build -o build/ -ldflags "-compressdwarf=false -linkmode external" .
}

check() {
  cd $pkgname-$pkgver
  go test ./...
}

package() {
  depends+=(
    libolm libolm.so
  )
  install -vDm 755 $pkgname-$pkgver/build/$pkgname -t "$pkgdir/usr/bin/"
  install -vDm 644 $pkgname-$pkgver/{CHANGELOG,README}.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
